package model.admin;

import java.sql.ResultSet;
import java.util.ArrayList;

import myutil.Connect;

import vo.*;
import vo.mixed.CourseListVo;

public class ModifyCoursesMo {

	public Boolean updateCourseDetails(CourseListVo CourseDetails) {
		String query = "update course_details" + "  set course_name	=	'"
				+ CourseDetails.getCourse_name() + "'," + "  	 course_code	=	'"
				+ CourseDetails.getCourse_code() + "' " + "where course_id		=	"
				+ CourseDetails.getCourse_id() + ";";
		Connect c = new Connect();
		System.out.println("Query is \t " + query + "\n");
		Boolean result;
		try {
			c.dml(query);
			result = true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result = false;
		}
		return result;
	}

	public Boolean deleteCourseDetails(int course_id) {

		String query = "";
		query = "update course_details set status=0 where course_id="
				+ course_id + ";";

		System.out.println(query);
		Connect c = new Connect();
		try {
			c.dml(query);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			return false;
		}
	}

	public Boolean addCourseDetails(CourseListVo CourseDetails, int batch_id) {
		// Adds new course to the courses list
		String query1 = "";
		if (batch_id != 0)
			query1 = "INSERT INTO degree_department(department_id, degree_id, batch_id, start_year, description,status) values "
					+ "((select department_id from course_details where course_name ='"
					+ CourseDetails.getCourse_name()
					+ "'), "
					+ "(select degree_id from degree_management where batch_id="
					+ batch_id
					+ "),"
					+ " "
					+ batch_id
					+ ","
					+ CourseDetails.getStart_year()
					+ ", "
					+ CourseDetails.getDescription() + ", 1); ";
		else
			query1 = "INSERT INTO course_details (course_name, duration, credit, lab, theory, start_year, department_id, course_code, status) VALUES "
					+ "('"
					+ CourseDetails.getCourse_name()
					+ "', "
					+ CourseDetails.getDuration()
					+ ", "
					+ CourseDetails.getCredit()
					+ ", "
					+ CourseDetails.getLab()
					+ ", "
					+ CourseDetails.getTheory()
					+ ", '"
					+ CourseDetails.getStart_year()
					+ "', "
					+ "(select department_id from department_details where department_name='"
					+ CourseDetails.getDepartment_name()
					+ "'), '"
					+ CourseDetails.getCourse_code() + "', '1');";
		System.out.println(query1);
		Connect c = new Connect();
		try {
			c.dml(query1);

			return true;
		} catch (Exception e) {
			// TODO: handle exception
			return false;
		}
	}

	public boolean removeCourseFromBatch(int course_id, int batch_id) {
		String query = "";
		query = "select c.course_name," + " c.course_code," + " c.course_id , "
				+ " dd.department_name, " + " dd.department_id"
				+ " from degree_department d, " + " course_details c, "
				+ " department_details dd "
				+ "where d.department_id	=	dd.department_id "
				+ "and c.department_id	=	d.department_id "
				+ "and d.batch_id		=	" + batch_id + ";";
		return true;
	}

	public boolean deleteCourseProfessor(int course_id, int professor_id) {
		String query = "update course_professor set professor_id_1=null where course_id="
				+ course_id + " and professor_id_1=" + professor_id + ";";
		String query1 = "update course_professor set professor_id_2=null where course_id="
				+ course_id + " and professor_id_2=" + professor_id + ";";
		String query2 = "update course_professor set professor_id_3=null where course_id="
				+ course_id + " and professor_id_3=" + professor_id + ";";
		String query3 = "update course_professor set professor_id_4=null where course_id="
				+ course_id + " and professor_id_4=" + professor_id + ";";

		Connect c = new Connect();
		System.out.println(query);
		try {
			c.dml(query);
			c.dml(query1);
			c.dml(query2);
			c.dml(query3);

			return true;
		} catch (Exception e) {
			// TODO: handle exception
			return false;
		}

	}

	public Boolean CourseProfessorCourseDetails() {
		String query = "";
		return false;
	}

	public Boolean addDepartmentCourseDetails(int department_id, String course_name) {
		String query = "";
		query = "UPDATE course_details " + " SET department_id="
				+ department_id + " " + "WHERE course_id=(select course_id from course_details where course_id=" + course_name + ");";

		Connect c = new Connect();
		System.out.println(query);
		try {
			c.dml(query);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			return false;
		}

	}
}
